package com.lk.pet.vet.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class VetControllerAdvice {

    @ExceptionHandler(value={Exception.class})
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public Object exceptHandle(Exception e){
        Map<String,Object> map=new HashMap<>();
        map.put("code", VetExceptionCode.COMMON);
        map.put("msg",e.getLocalizedMessage());
        return map;
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(value={VetBaseException.class})
    public Object exceptHandle(VetBaseException e){
        Map<String,Object> map=new HashMap<>();
        map.put("code", e.getCode());
        map.put("msg",e.getMessage());
        return map;
    }
}
